package cn.seaboot.admin.user.web;

import cn.seaboot.admin.mvc.argument.Params;
import cn.seaboot.admin.user.bean.Permit;
import cn.seaboot.admin.user.context.UserContext;
import cn.seaboot.admin.user.service.PermitService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * 菜单编辑
 * <p>dir 菜单树编辑
 * <p>grant 菜单树角色分配
 * <p>@author Mr.css on 2018-6-20
 */
@Controller
@RequestMapping("sys/permit")
@Tag(name = "系统操作权限 [t_sys_permit] 管理")
public class PermitCtrl {

    @Resource
    private PermitService permitService;

    @Resource
    private UserContext userContext;

    /**
     * 增
     *
     * @param pid pojo
     * @return affected rows
     */
    @ResponseBody
    @Operation(description = "系统操作权限 [t_sys_permit] 增")
    @RequestMapping(value = "info", method = RequestMethod.POST)
    public Permit addDir(@Params String pid) {
        return permitService.insert(userContext.getUserDeptId(), pid);
    }


    /**
     * 删
     *
     * @param id ID
     * @return affected rows
     */
    @ResponseBody
    @Operation(description = "系统操作权限 [t_sys_permit] 删")
    @RequestMapping(value = "info", method = RequestMethod.DELETE)
    public int deleteInfo(@Params String id) {
        return permitService.deleteById(id);
    }

    /**
     * 改
     *
     * @param perm pojo
     * @return affected rows
     */
    @ResponseBody
    @Operation(description = "系统操作权限 [t_sys_permit] 改")
    @RequestMapping(value = "info", method = RequestMethod.PUT)
    public int updateInfo(@Params String id, Permit perm) {
        return permitService.updateSampleById(perm);
    }

    /**
     * 查列表
     *
     * @return affected rows
     */
    @ResponseBody
    @Operation(description = "系统操作权限 [t_sys_permit] 列表查询")
    @RequestMapping(value = "list", method = RequestMethod.GET)
    public List<Permit> queryList() {
        return permitService.queryList();
    }
}
